<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../component/pear/css/pear.css" />
	<link rel="stylesheet" href="../../admin/css/other/person.css" />
</head>
<body class="pear-container">
	<div class="layui-row layui-col-space10">

			<div class="layui-card">

				<form class="layui-form" action="" onsubmit="return false" id="user-info" lay-filter="user-info">
					<input name="id" hidden>

					<div class="layui-form-item">
						<label class="layui-form-label">名称</label>
						<div class="layui-input-block">
							<input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名称" autocomplete="off" class="layui-input">
						</div>
					</div>


					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="text" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
						</div>
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label">年龄</label>
						<div class="layui-input-block">
							<input type="text" name="age" required  lay-verify="required" placeholder="请输入年龄" autocomplete="off" class="layui-input">
						</div>
					</div>
										
					<div class="layui-form-item">
					   <label class="layui-form-label">性别</label>
					   <div class="layui-input-block">
							<input type="radio" name="sex" value="1" title="男">
							<input type="radio" name="sex" value="2" title="女" checked>						   
					   </div>						  
					</div>
				

					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">地址</label>
						<div class="layui-input-block">
							<textarea name="schoolAddress" placeholder="请输入用户地址" class="layui-textarea"></textarea>
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit lay-filter="save">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>

				<div style="height: 45px;border-top: 1px whitesmoke solid;text-align: center;line-height: 45px;font-size: 13.5px;">
					<span>家教平台 ，欢迎您</span>
				</div>
			</div>


	</div>
	<script src="../../component/layui/layui.js"></script>
	<script src="../../component/pear/pear.js"></script>
	<script src="../../api/baseApi.js"></script>
	<script src="../../api/userApi.js"></script>
	<script src="../../component/js/core.util.js"></script>
	<script>
		layui.use(['jquery', 'element', 'layer', 'convert','form'], function () {
			var element = layui.element,
				layer = layui.layer,
				$ = layui.jquery,
					form = layui.form,
				convert = layui.convert;

			let MODULE_PATH = "operate/";
			
			var image = new Image();
			image.src = "../../admin/images/avatar.jpg";
			image.onload = function() {
				$("#userAvatar").attr("src", convert.imageToBase64(image));
			}
			
			window.callback = function (data) {
				layer.close(data.index);
                $("#userAvatar").attr("src", data.newAvatar);
            }

			$("#userAvatar").click(function () {
				layer.open({
					type: 2,
					title: '更换图片',
					shade: 0.1,
					area: ["900px", "500px"],
					content: MODULE_PATH + 'profile.html',
					btn: ['确定', '取消'],
					yes: function (index, layero) {
						window['layui-layer-iframe' + index].submitForm();
					}
				});
			});

			var userId = coreUtil.getLocalData("userId");

			coreUtil.sendAjax(getUrl + userId, null, function (res) {
				console.log(res.data);

				form.val('user-info', {
					'id': res.data.id,
					'username':res.data.username,
					'password':res.data.password,
					'sex': res.data.sex,
					'age': res.data.age,
					'schoolAddress': res.data.schoolAddress
				})

			}, 'GET')
			
			
			// 保存提 交
			form.on('submit(save)', function(data) {
				coreUtil.sendAjax(updateUrl, JSON.stringify(data.field), function (res) {
					console.log(res.data);
					
				}, 'POST');
				/// 动画
				return false;
			});
			
			

		});
	</script>
</body>
</html>
